package com.example.dou2204.frag;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.SPUtils;
import com.bumptech.glide.Glide;
import com.example.dou2204.R;
import com.example.dou2204.adapter.FragAdapter;
import com.example.dou2204.adapter.TuiVideoAdapter;
import com.example.dou2204.baseMVVM.BaseFragment;
import com.example.dou2204.baseMVVM.BaseViewFragment;
import com.example.dou2204.databinding.FragmentMineBinding;
import com.example.dou2204.entity.MyCustomTabEntity;
import com.example.dou2204.entity.VideoEntity;
import com.example.dou2204.frag.mime.DianzanFragment;
import com.example.dou2204.frag.mime.ShoucangFragment;
import com.example.dou2204.tuijian.TuijianViewModel;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.wildma.pictureselector.PictureBean;
import com.wildma.pictureselector.PictureSelector;

import java.util.ArrayList;
import java.util.List;


public class MineFragment extends BaseViewFragment<FragmentMineBinding> {

    List<Fragment> list = new ArrayList<>();
    ArrayList<CustomTabEntity> tabs = new ArrayList<>();
    FragAdapter fragAdapter;

    public MineFragment() {
        // Required empty public constructor
    }


    @Override
    protected void initData() {
       list.add(new DianzanFragment());
       list.add(new ShoucangFragment());
       fragAdapter = new FragAdapter(getActivity(),list);
       binding.vp.setAdapter(fragAdapter);

       tabs.add(new MyCustomTabEntity("点赞",0,0));
       tabs.add(new MyCustomTabEntity("收藏",0,0));
       binding.common.setTabData(tabs);

       binding.vp.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
           @Override
           public void onPageSelected(int position) {
               super.onPageSelected(position);
               binding.common.setCurrentTab(position);
           }
       });
       binding.common.setOnTabSelectListener(new OnTabSelectListener() {
           @Override
           public void onTabSelect(int position) {
               binding.vp.setCurrentItem(position);
           }

           @Override
           public void onTabReselect(int position) {

           }
       });

       binding.exit.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               SPUtils.getInstance().clear();//清空登录人的保存信息
               getActivity().finish();//退出项目
           }
       });
       binding.ivTou.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               PictureSelector.create(getActivity(),300).selectPicture();
           }
       });
    }

    @Override
    protected void initView() {

    }

    @Override
    protected int bindLayout() {
        return R.layout.fragment_mine;
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==300&&resultCode== Activity.RESULT_OK){
            PictureBean o = (PictureBean) data.getExtras().get(PictureSelector.PICTURE_RESULT);
            Glide.with(getContext()).load(o.getPath()).into(binding.ivTou);
        }
    }
}